<?php

// +----------------------------------------------------------------------
// | 权限组控制器
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 微尘 <yicmf@qq.com>
// +----------------------------------------------------------------------

namespace app\controller\pos\admin;

use app\model\pos\PosTransfer as PosTransferModel;
use yicmf\builder\Edit;
use yicmf\builder\Table;
use app\controller\admin\Common;
use yicmf\builder\View;

class PosTransfer extends Common
{
    protected function initialize()
    {
        parent::initialize(); 
    }

    public function _filter()
    {
        $where[] = ['status', '>', -2];
        return $where;
    }

    public function index()
    {
        $where = $this->_filter();
        // 显示页面
        $builder = new Table();
        $builder->model(PosTransferModel::class)
            ->where($where)
            ->order('id DESC')
//                ->suggest('高等级可以对低等级用户进行操作或者授权')
            ->searchText('title', '标签名称：')
//            ->buttonUpdate('update','划转')
            ->keyId()
//            ->keyTitle('标签名称')
            ->keyText('name','划转数量')
            ->keyText('pos_num','划拨数量')
            ->keyText('pos_level_id','可得等级')
            ->keyUser('user_id','原用户')
            ->keyUser('to_user_id','接收用户')
//				->keyText('description', '描述')
				->keyUpdateTime('划拨时间')
//            ->keyStatus()
//            ->quickUpdate(['title','description'])
//				->actionUpdate()
                ->actionForbid( 'forbid?id={$id}', '回退')
            ->actionView();
//            ->actionForbid('forbid?id={$id}', '禁用', function ($data) {
//                return 1 == $data['status'] && 1 < $data['id'];
//            });
        return $builder->fetch();
    }

//
//    public function update()
//    {
//        if ($this->request->isPost()) {
//           $event = new \app\event\pos\PosTransfer();
//           $data = $event->gift($this->request->param(),$this->user);
//            if (0 === $data['code']) {
//                $this->_returnSuccess($data['message']);
//            } else {
//                $this->_returnError($data['message'], false);
//            }
//        } else {
//            // 同步节点与菜单
//
//            $data = [];
//            $vips = \app\model\pos\PosLevel::where('status',1)->column('title','id');
//            $data['pos_level_id'] = array_key_first($vips);
//                $builder = new Edit();
//                $builder->title('新增划转')
//                    ->keyTextInline('username', '接收会员账号')
//                    ->keyTextInline('name','pos名称')
//                    ->keyTextInline('model','pos型号')
//                    ->keyTextArea('pos_sn','pos序列号','pos机序列号，每行一个。')
//                    ->data($data)
//                    ->buttonSubmit();
//                return $builder->fetch();
//        }
//    }

    public function view()
    {

        $data = PosTransferModel::where('id', $this->request->param('id'))->find();

        $data['pos_sns'] = implode(' ', $data['pos_sn']);
                $builder = new View();
                $builder->title('划转详情')
                    ->keyLabel('pos_level.title','划赠VIP')
                    ->keyLabel('pos_num', '划转数量', '');


        $builder->keyLabel('pos_sns', '划转序列号', '')
                    ->keyLabel('create_time', '划转时间', '')
                    ->data($data);
                return $builder->fetch();
    }


}
